package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.MarketManagementDaoPool;
import com.sc.nft.mapper.MarketManagementDaoPoolMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Author：LiGen
 * @Package：com.sc.nft.dao
 * @Project：sc_metago
 * @name：MarketManagementDaoPoolDao
 * @Date：2024/7/23 20:04
 * @Filename：MarketManagementDaoPoolDao
 */
@Slf4j
@Repository
public class MarketManagementDaoPoolDao extends ServiceImpl<MarketManagementDaoPoolMapper, MarketManagementDaoPool> {

    /**
     * 获取
     *
     * @param ecologyHatchId
     * @return
     */
    public MarketManagementDaoPool getOneByEcologyHatchId(Long ecologyHatchId, Long collectionId, Long daoId, Date now) {
        return baseMapper.getOneByEcologyHatchId(ecologyHatchId, collectionId, daoId, now);
    }

    /**
     * 获取时间内的池子
     * @param now
     * @return
     */
    public List<MarketManagementDaoPool> getLastPools(Date now){
        return baseMapper.getLastPools(now);
    }

    /**
     * 获取没有结算的池子  当前机制不存在在当前结算月份之前多个不结算的池子
     *
     * @param ecologyHatchId
     * @return
     */
    public MarketManagementDaoPool getLockPool(Long ecologyHatchId, Long collectionId, Long daoId,Long settlePoolId,Date settlePoolStartTime) {
        return baseMapper.getLockPool(ecologyHatchId, collectionId, daoId, settlePoolId,settlePoolStartTime);
    }

    /**
     * 添加冻结金额
     *
     * @param id
     * @param amount
     * @return
     */
    public Boolean addAmount(Long id, BigDecimal amount) {
        return baseMapper.addAmount(id, amount);
    }


    public boolean updateIsSettleById(Long id, Boolean isSettle) {
        LambdaUpdateWrapper<MarketManagementDaoPool> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(MarketManagementDaoPool::getId, id);
        wrapper.set(MarketManagementDaoPool::getIsSettle, isSettle);
        return update(new MarketManagementDaoPool(), wrapper);
    }
}
